package com.leetcode.August;

import javax.swing.tree.TreeNode;

/**
 * @Description: 543. 二叉树的直径
 * @Author: Mr.Fxy
 * @CreateTime: 2024-08-30 16:15
 */
public class LC543二叉树的直径 {
    int ans=0;
    public int diameterOfBinaryTree(TreeNode root) {
        search(root);
        return ans;
    }
    public int search(TreeNode root){
        if (root==null) return 0;
        int left=search(root.left);
        int right=search(root.right);
        ans=Math.max(ans,left+right);
        return Math.max(left,right)+1;
    }
}
